import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:xin_nuo_pda/base/BaseController.dart';
import 'package:xin_nuo_pda/bean/lot_entity.dart';
import 'package:xin_nuo_pda/bean/lot_id_entity_entity.dart';
import 'package:xin_nuo_pda/http/api/lot_api.dart';
import 'package:xin_nuo_pda/routes/Routes.dart';

class StartWorkNextDBController extends BaseController {

  late List<LotBOMLINELIST> mainLotList;
  late List<LotBOMLINELIST> stepLotList;
  late LotEntity lotEntity;

  @override
  void onInit() {
    super.onInit();
    lotEntity = Get.arguments ?? LotEntity();
    mainLotList = lotEntity.MAINBOMLINELIST ?? [];
    stepLotList = lotEntity.bOMLINELIST ?? [];
  }

  trackIn() async{
    List<LotIdEntity> data = [];
    LotIdEntity info = LotIdEntity();
    info.lOTID = lotEntity.lOTID;
    data.add(info);
    Map<String, dynamic> params = {'ACTIONTYPE':'DefaultTrackIn','ISCHECKSTEPAUTHORITY':'true','EQUIPMENTID':lotEntity.eQUIPMENTID ?? '','LOTLIST':data,
          'MAINMLOTLIST' :mainLotList,'STEPMLOTLIST' : stepLotList };
    var result = await LotApi.trackIn(canelToken,params: params);
    if(result.ok){
      Fluttertoast.showToast(
        msg: "进站成功",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
      );

      Get.offAllNamed(Routes.Tabs);
    }
  }

  materialInfo(int index) async{
    Map<String, dynamic> params = {'MLOTID':''};
    var result = await LotApi.materialInfo(canelToken,params: params);
    if(result.ok) {
      if (mainLotList[index].mATERIALNAME == result.data?.mATERIALNAME &&
          mainLotList[index].mATERIALTYPE == result.data?.mATERIALTYPE
          && mainLotList[index].uOMID == result.data?.uOMID) {
        // if (index < mainLotList.length - 1) {
        //   // FocusScope.of(Get.context!).requestFocus(focusNodeList[index + 1]);
        // }
      } else {
        Get.snackbar('提示', '验证失败');
      }
    }else{
    }
  }
}
